import { request } from "@/utils/service"
import type * as Jira from "./types/jira"

/** 查 */
export function getJiraDataApi(data: Jira.JiraRequestData) {
  return request<Jira.JiraResponseData>({
    url: "jira/list",
    method: "post",
    data
  })
}

//  jira 号是否在本系统存在
export function checkCodeRepeat(code: string, id: number) {
  return request<ApiResponseData<boolean>>({
    url: `jira/checkCode/${id}/${code}`,
    method: "post"
  })
}

//  检测jira号是否存在，先在本系统查询，后去jira系统查询
export function checkCodeExist(code: string) {
  return request<ApiResponseData<boolean>>({
    url: `jira/exist/${code}`,
    method: "post"
  })
}

/** 保存 */
export function saveJiraDataApi(data: Jira.JiraData) {
  return request({
    url: "jira/save",
    method: "post",
    data
  })
}
/** 根据jira号导入jira */
export function importJiraApi(projectId: number, code: string) {
  return request({
    url: `/jira/import/${projectId}/${code}`,
    method: "post"
  })
}
/** 导入多个jira号 */
export function importJirasApi(data: Jira.JiraImportData) {
  return request<ApiResponseData<string>>({
    url: `/jira/importJiras`,
    method: "post",
    data
  })
}

/** 批量修改jira的所属项目 */
export function batchUpdateProjectId(data: Jira.JiraImportData) {
  return request<ApiResponseData<number>>({
    url: `/jira/batchUpdateProjectId`,
    method: "post",
    data
  })
}

/** 删 */
export function deleteJiraDataApi(id: number) {
  return request({
    url: `jira/delete/${id}`,
    method: "post"
  })
}
/** 根据jira号统计工时信息 */
export function summaryJira(code: string) {
  return request<ApiResponseData<void>>({
    url: `jira/summary/${code}`,
    method: "get"
  })
}

/** 根据jira号统计工时信息 */
export function reportJiraDetail(code: string) {
  return request<ApiResponseData<Jira.JiraReportDetailData>>({
    url: `jira/reportDetail/${code}`,
    method: "get"
  })
}

/** 根据项目查询当前人的可用jira列表 selectByProjectId */
export function selectJiraByProjectId(projectId: number, isSub: boolean = false) {
  return request<ApiResponseData<Jira.JiraData[]>>({
    url: "jira/selectByProjectId",
    method: "get",
    params: {
      projectId,
      isSub
    }
  })
}

/** 统计全部工时，慎用 */
export function summaryAllJiraApi() {
  return request<ApiResponseData<number>>({
    url: `/jira/summaryAll`,
    method: "get"
  })
}

export function clearPlanDate(id: number) {
  return request<ApiResponseData<number>>({
    url: `/jira/clearPlanDate/${id}`,
    method: "post"
  })
}
